package smartbooks.ui.invoices;

import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Ankit
 */
public class MyInvoiceLinesModel extends DefaultTableModel {
    private final String[] columnNames = {"No","Qty","Item Name","Item Code","Description","Selling Price","Tax","Total"};
    
    private ArrayList<String[]> invoiceLines = (ArrayList)Arrays.asList(
        new String[]{"","","","","","","",""},
        new String[]{"","","","","","","",""},
        new String[]{"","","","","","","",""},
        new String[]{"","","","","","","",""},
        new String[]{"","","","","","","",""},
        new String[]{"","","","","","","",""},
        new String[]{"","","","","","","",""},
        new String[]{"","","","","","","",""}
    );
    
    @Override
    public int getColumnCount() {
        return columnNames.length;
    }
    
    @Override
    public int getRowCount() {
        return invoiceLines.size();
    }
    
    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }
    
    @Override
    public Object getValueAt(int row, int col) {
        return (invoiceLines.get(row))[col];
    }
    
    /*
     * Don't need to implement this method unless your table's
     * editable.
     */
    @Override
    public boolean isCellEditable(int row, int col) {
        return col!=0 && col!=7;
    }
    
    /*
     * Don't need to implement this method unless your table's
     * data can change.
     */
    @Override
    public void setValueAt(Object value, int row, int col) {
        String[] column = invoiceLines.get(row);
        column[col] = (String)value;
        invoiceLines.set(row, column);
        fireTableCellUpdated(row, col);
    }
    
    public void setColumn(int row, String[] column) {
        invoiceLines.set(row, column);
        fireTableDataChanged();
    }
}